import { Component, OnInit } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {CheckloginService} from "../../../services/checklogin.service";
import {Router} from "@angular/router";

@Component({
  selector: 'app-goodslist',
  templateUrl: './goodslist.component.html',
  styleUrls: ['./goodslist.component.scss']
})
export class GoodslistComponent implements OnInit {

  constructor( private http: HttpClient, private router: Router) { }
  // 存放页面商品信息
  public imgArr: any = [
    ];

  ngOnInit( ) {
    const url = 'http://192.168.2.228:8080/goods/list';
    this.http.get(url).subscribe( result => {
      this.imgArr = result['data']['list'];
    });
  }
  goDetail(id) {
    if (!localStorage.user) {
      this.router.navigate(['/login']);
    } else {
      this.router.navigate(['/goodsdetails', id]);
    }
  }

}
